package com.ftg.learn.chapter04.linetable;

import java.util.Arrays;

/**
 * 栈  数组
 *
 * @author 布衣
 */
public class StackForMe {

    int[] stack;

    private int top = -1;

    public StackForMe() {
        stack = new int[10];
    }

    /**
     * 压栈
     */
    public void push(int val) {
        if (top == stack.length - 1) {
            int newLen = stack.length * 2 > Integer.MAX_VALUE - 8 ? Integer.MAX_VALUE : stack.length * 2;
            stack = Arrays.copyOf(stack, newLen);
        }
        stack[++top] = val;
    }

    /**
     * 弹栈
     *
     * @return int
     */
    public int pop() {
        return stack[top--];
    }

    public int size() {
        return top + 1;
    }

    public static void main(String[] args) {
        StackForMe stack = new StackForMe();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());

        //1 写完
        //2 链表操作
        //3 分析一下才刚那个题  “（【{}】）”  “)(){[]}” leecode :20

        // 滑动窗口  |  接雨水
    }

}
